<%-- 
    Document   : content
    Created on : Oct 13, 2011, 1:42:40 PM
    Author     : HIT
--%>
<%@page import="POJO.Thamso"%>
<%@page import="POJO.Hinhanh"%>
<%@page import="POJO.Sanpham"%>
<%@page import="POJO.Gianhang"%>
<%@page import="BUS.ThamsoBUS"%>
<%@page import="java.util.List"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>


    </head>
    <body>
        <div align="center">
            <%                
                if (request.getAttribute("lstGianhang") != null) {
                    
                    List<Gianhang> ds1 = (List<Gianhang>) request.getAttribute("lstGianhang");
                    
                    
                    
                    int soLuongSanPhamTrenTrang=Integer.parseInt(request.getAttribute("soLuong").toString());
                    int soTrang = ds1.size() / soLuongSanPhamTrenTrang;
                    if (ds1.size() % soLuongSanPhamTrenTrang != 0) {
                        soTrang++;
                    }
                    
                    for (int i = 1; i <= soTrang; i++) {
            %>

            <a id="kieumoi" href="index2.html&Trang=<%=i%>"><%= i%></a>
            <%            
                }
                }
            %> 
            
        </div>
        <div class="body-content">
            <div style="width:988px; overflow:hidden">
                <!--<div>-->
                <!--one deal-->

                <!--end one deal-->
                <div id="dListDeal" class="all-content"> 

                    <%                        
                        List<Gianhang> dsgh = (List<Gianhang>) request.getAttribute("lstGianhang");
                        if (dsgh != null) {
                            List<Sanpham> dssp = (List<Sanpham>) request.getAttribute("lstSanpham");
                            List<Hinhanh> dsha = (List<Hinhanh>) request.getAttribute("lstHinhAnh");
                            for (int i = 0; i < dsgh.size(); i++) {
                                String tenSanPham = dssp.get(i).getTenSanPham();
                                String duongdan = dsha.get(i).getDuongDan();
                                String giaBan = dsgh.get(i).getGiaBan().toString();
                                String khuyenMai = dsgh.get(i).getKhuyenMai().toString();
                                String gioiThieu = dssp.get(i).getGioiThieu();
                                String magh=dsgh.get(i).getMaGianHang();
                    %>
                    <div class="small-box-white">    
                        <h3>
                            <a href="chitietsanpham.html?Magh=<%=magh %>" name="<%=tenSanPham%>"><%=tenSanPham%></a>
                        </h3>   
                        <div class="small-box-img">   
                            <a href="chitietsanpham.html?Magh=<%=magh %>" name="<%=tenSanPham%>">
                                <img src="<%=duongdan%>" alt="<%=tenSanPham%>" 
                                     title="<%=tenSanPham%>" height="166" width="268"></a>                     	     <i></i>   </div>   <div class="small-box-text">       	<p>
                                <%=gioiThieu%></p>   
                        </div>  
                        <div class="small-box-button">      
                            <a href="chitietsanpham.html?Magh=<%=magh %>" name="<%=tenSanPham%>" class="view-button"></a>  

                        </div>   
                        <div class="small-box-sale">     
                            <p><%=giaBan%><span>VNĐ</span></p>      
                            <div class="small-box-save">          
                                <span class="number"><%=khuyenMai%>%</span>         
                                <span>tiết kiệm</span>      
                            </div>     
                            <div class="small-box-price">          
                                <span class="number" id="Time_CountDown_<%=i%>">
                                </span>         
                                <span>ngày hết hạn</span>      
                            </div>   
                        </div> 	
                        <div class="clear"></div>        
                    </div>
                    <% }
                        }%>

                </div>
                <!--</div>-->

            </div>
            <div class="clear"></div>
        </div>
        <script type="text/javascript">
            var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") 
            var dateFuture =new Array();
            <%                
                for (int i = 0; i < dsgh.size(); i++) {
                    String tam = dsgh.get(i).getNgayHetHan().toString();
                    String[] arr = tam.split("-");
            %>
                yr=<%=arr[0]%>;
                mo=<%=arr[1]%>;
                da=<%=arr[2]%> ;
                futurestring=montharray[mo-1]+" "+da+", "+yr ;
                dateFuture[<%=i%>]=Date.parse(futurestring);
            <%                    
                }
            %>
           
        </script>
        <script type="text/javascript">
            
            function GetCount(ddate,iid){

                dateNow = new Date();    //grab current date
                amount = ddate - dateNow.getTime();    //calc milliseconds between dates
                delete dateNow;

                // if time is already past
                if(amount < 0){
                    document.getElementById(iid).innerHTML="Hết hạn !";
                }
                // else date is still good
                else{
                    days=0;hours=0;mins=0;secs=0;out="";

                    amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

                    days=Math.floor(amount/86400);//days
                    amount=amount%86400;

                    hours=Math.floor(amount/3600);//hours
                    amount=amount%3600;

                    mins=Math.floor(amount/60);//minutes
                    amount=amount%60;

                    secs=Math.floor(amount);//seconds

                    if(days > 0)
                    {
                        out += days +" "+((days==1)?"ngày":"ngày");
                    }
                    else
                    {
                        if(hours != 0)
                        {
                            out += hours +" "+((hours==1)?"":"")+":";
                        }
                        out += mins +" "+((mins==1)?"":"")+":";
                        out += secs +" "+((secs==1)?"":"");
                        
                    }
                    
                    document.getElementById(iid).innerHTML=out;

                    setTimeout(function(){GetCount(ddate,iid)}, 1000);
                }
            }

            window.onload=function(){
            <%                
                for (int i = 0; i < dsgh.size(); i++) {
            %>
                    GetCount(dateFuture[<%=i%>], 'Time_CountDown_<%=i%>');
                
            <%                    
                }
            %>
                    //you can add additional countdowns here (just make sure you create dateFuture2 and countbox2 etc for each)
                };
        </script>                            
    </body>
</html>
